﻿using System;

namespace JQuery.WebKit
{
    public class JComboItem 
    {
        private JCombo _parent;
        public string Text { get; set; }
        public string Value { get; set; }
        public bool Selected { get; set; }
        public string Group { get; set; }
        public bool Disabled { get; set; }

        public JComboItem()
        {
        }

        public JComboItem(JCombo parent, string text)
        {
            Text = text;
            _parent = parent;
        }

        public JComboItem(JCombo parent, string text, object value)
        {
            Text = text;
            Value = value.ToString();
            _parent = parent;
        }

        public override string ToString()
        {
            if (string.IsNullOrEmpty(Text))
            {
                throw new ArgumentNullException("Text cannot be empty.");
            }
            string sel = Selected ? "selected=\"selected\" " : "";
            string disabled = Disabled || _parent.Disabled ? "disabled=\"disabled\" " : "";
            string val = !string.IsNullOrEmpty(Value) ? string.Format(" value=\"{0}\" ", Value) : " ";
            return string.Format("<option{0}{1}{2}>{3}</option>", val, sel, disabled, Text);
        }
    }
}
